package web

import (
	"night-talk/dbcon"

	"github.com/gin-gonic/gin"
	"github.com/jinzhu/gorm"
)

// InitRoute ...
func InitRoute(r *gin.Engine, db *gorm.DB) {
	r.POST("/user/register", func(c *gin.Context) {
		dbcon.DBregister(c, db)
	})

	r.POST("/user/login", func(c *gin.Context) {
		dbcon.DBlogin(c, db)
	})

	r.GET("/user", func(c *gin.Context) {
		dbcon.DBgetUsersInfo(c, db)
	})

	r.GET("/user/:username", func(c *gin.Context) {
		dbcon.DBgetAUserInfo(c, db)
	})

	r.PATCH("/user/:username", func(c *gin.Context) {
		dbcon.DBpatchAUserInfo(c, db)
	})

	r.PATCH("/score/:username", func(c *gin.Context) {
		dbcon.DBdeductScore(c, db)
	})

	r.GET("/picture/:picname", func(c *gin.Context) {
		dbcon.DBgetAPicture(c, db)
	})

	////////////////////////////////
	r.POST("/audio", func(c *gin.Context) {
		dbcon.DBpostAaudio(c, db)
	})

	r.GET("/wav/:filename", func(c *gin.Context) {
		dbcon.DBgetAWav(c, db)
	})

	/////////Rooms
	r.POST("/room/join", func(c *gin.Context) {
		dbcon.DBpostRoomJoin(c, db)
	})

	r.GET("/room/check/:roomid", func(c *gin.Context) {
		dbcon.DBgetRoomIsFull(c, db)
	})

	r.POST("/room/cancel", func(c *gin.Context) {
		dbcon.DBpostRoomUserCancel(c, db)
	})

	r.GET("/room/audios/:roomid", func(c *gin.Context) {
		dbcon.DBgetRoomAudios(c, db)
	})

	r.POST("/room/audios", func(c *gin.Context) {
		dbcon.DBpostForRoomUserAudio(c, db)
	})

}
